package com.zjh.userserver.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zjh.common.R;
import com.zjh.entity.User;
import com.zjh.userserver.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * ClassName: UserController
 * Description:
 * @Author zjh
 * @Create 2023/10/10 8:35
 */
@RestController
@RequestMapping("/user")
public class UserController {
	
	@Autowired
	private UserMapper userMapper;
	
	@GetMapping("/findAll/{begin}/{pagesize}")
	public R<List<User>> findAllUser(@PathVariable("begin") Integer begin, @PathVariable("pagesize") Integer pagesize) {
		
		return new R<>(0, "", Math.toIntExact(userMapper.selectCount(null)), userMapper.findAll(begin, pagesize));
	}
	
	@DeleteMapping("/deleteById/{id}")
	public void deleteById(@PathVariable("id") Integer id){
		userMapper.deleteById(id);
	}
	
	@PostMapping("/save")
	public void saveOne(@RequestBody User user){
		 userMapper.insert(user);
	}
}
